package br.edu.ufcg.dsc.psoo.mymoney.controller;

import java.util.List;

import br.edu.ufcg.dsc.psoo.mymoney.controller.exceptions.AccountNotFoundException;
import br.edu.ufcg.dsc.psoo.mymoney.controller.exceptions.InvalidAccountException;
import br.edu.ufcg.dsc.psoo.mymoney.controller.exceptions.InvalidUserException;
import br.edu.ufcg.dsc.psoo.mymoney.model.bean.Account;
/**
 * Interface do controller respons�vel pela valida��o e opera��es envolvendo contas
 * 
 * @author leonardo
 * 
 */
public interface AccountController {

	/**
	 * Calcula saldo da conta
	 * 
	 * @param userId
	 *            id do usu�rio logado
	 * @param accountId
	 *            identificador da conta
	 * @return float saldo
	 * @throws InvalidUserException usu�rio inv�lido
	 * @throws InvalidAccountException conta inv�lida
	 * @throws AccountNotFoundException conta n�o encontrada
	 */
	public abstract float balance(Long userId, Long accountId)
			throws InvalidUserException, InvalidAccountException,
			AccountNotFoundException;

	/**
	 * Fecha sess�o do Hibernate utilizada na instancia local de AccountDAO
	 */
	public abstract void closeSession();

	/**
	 * Valida e cria nova conta
	 * 
	 * @param account
	 * @return Account conta criada no banco
	 * @throws InvalidAccountException
	 */
	public abstract Account create(Account account)
			throws InvalidAccountException;

	/**
	 * Valida e deleta conta
	 * 
	 * @param id
	 *            identificador da conta
	 * @param userId
	 *            id do usu�rio logado
	 * @throws InvalidAccountException
	 * @throws AccountNotFoundException
	 */
	public abstract void delete(Long id, Long userId)
			throws InvalidAccountException, AccountNotFoundException;

	/**
	 * Abre sess�o do Hibernate utilizada na instancia local de AccountDAO
	 */
	public abstract void openSession();

	/**
	 * Seta SessionFactory criado no ApplicationManager
	 * 
	 * @param sf
	 *            SessionFactory
	 */
//	public abstract void setSessionFactory(SessionFactory sf);

	/**Retorna todos as contas cadastradas para um usu�rio informado
	 * @param userId identificador do usu�rio
	 * @return lista de contas
	 */
	public abstract List<Account> listAll(Long userId);

	/**
	 * Valida e atualiza conta
	 * 
	 * @param account
	 * @return conta Account
	 * @throws InvalidAccountException
	 */
	public abstract Account update(Account account)
			throws InvalidAccountException;
	
	//TODO javadoc
	public Account findByName(String name);
	//TODO javadoc
	public Account loadById(Long id);

}